﻿//-----------------------------------------------------------------------
// <copyright file="LocalizableControls.cs" company="INL sprl">
//     Copyright 2009-2010 INL sprl.
// </copyright>
//-----------------------------------------------------------------------

namespace ParseXAML
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml;
    using System.Xml.Serialization;

    internal class LocalizableControls
    {
        protected Global global;

        private LocalizableAssembly assemblies;

        internal LocalizableControls(Global global, LocalizableAssembly assemblies)
        {
            this.global = global;
            this.assemblies = assemblies;
        }
        
        /// <summary>
        /// Cherches la liste des propriétés à traduire pour un contrôle
        /// </summary>
        /// <param name="dllName">Nom de l'assembly qui contient la DLL</param>
        /// <param name="typeName">Nom complet de la classe du contrôle (System.Control.TextBox)</param>
        /// <returns>Retourne la liste des propriétés</returns>
        internal List<string> GetLocalizableProperties(NamespaceAssociation association, string typeName)
        {
            List<string> o = null;
            if (assemblies == null)
            {
                o = new List<string>();
                LocalizableControl l;
                if (this.global.LocalizableControlsAndProperties.IncludeProperties.TryGetValue(string.Empty, out l))
                {
                    o.AddRange(l.Properties);
                }

                if (this.global.LocalizableControlsAndProperties.IncludeProperties.TryGetValue(typeName, out l))
                {
                    o.AddRange(l.Properties);
                }

                if (this.global.LocalizableControlsAndProperties.ExcludeProperties.TryGetValue(typeName, out l))
                {
                    foreach (var s in l.Properties)
                    {
                        o.Remove(s);
                    }
                }
            }
            else
            {
#if ANALYSE_ASSEMBLY
                Type typ = assemblies.GetType(association, typeName);
                if ( typ != null )
                    o = (new LocalizableControl(typ)).Properties; // TODO : to cache ;)
#endif
            }

            return o;
        }
    }
}
